package com.ruoyi.quartz.task;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.cs.domain.*;
import com.ruoyi.cs.domain.vo.TBackPackVo;
import com.ruoyi.cs.domain.vo.TbattleCreateVo;
import com.ruoyi.cs.mapper.*;
import com.ruoyi.cs.service.*;
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.mapper.SysConfigMapper;
import com.ruoyi.system.service.ISysDictDataService;
import com.ruoyi.system.service.ISysDictTypeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 定时任务调度测试
 *
 * @author ruoyi
 */
@Component("zbtTask")
@SuppressWarnings("all")
public class ZBTTask
{
    private static final Logger log = LoggerFactory.getLogger(ZBTTask.class);
    @Autowired
    private TBackpackMapper tBackpackMapper;
    @Autowired
    private CommonService commonService;
    @Autowired
    private ITGoodsPoolService tGoodsPoolService;

    /**
     * 定时扫描已取回成功的饰品，设置其交易价格
     */
    public void tradedOrderQuery() {
        /**每次获取部分已完成交易的订单*/
        List<String> orderIds = tBackpackMapper.tradedBackList();
        int count = 0;
        int failcount = 0;
        if(orderIds.size()>0){
            for (String orderId : orderIds) {
                try {
                    commonService.queryTradedOrderV2(orderId);
                    count++;
                }catch (Exception e){
                    log.error("已完成交易订单查询交易价格异常:{},订单ID：{}",e.getMessage(),orderId);
                    failcount++;
                }
            }
        }
        log.info("已完成交易订单查询交易报价总个数:{},成功个数:{},失败个数:{}",orderIds.size(),count,failcount);
    }

    /**
     * @Desc: 自动更新饰品池饰品价格
     * @author: zz
     * @date: 2024/2/5
     */
    public void updateGoodsPoolPrice(){
        tGoodsPoolService.updateGoodsPoolPrice();
    }
}
